# try:
#     fp = open("2332222.txt")
#     fp.read()
# except FileNotFoundError:
#     print("打开文件不存在！")


# print("打开文件成功！！")

# try:
#     fp = open("test")
#     a = 1/0
#     print(a)
#     fp.read()
# except (FileNotFoundError, ZeroDivisionError):
#     print("打开文件不存在！")
# except Exception as e:  #  别名
#     print(e)

# try:
#     fp = open("test")
#     a = 1/0
# except Exception as e:
#     print(e)
# finally:
#     print("不管什么都执行")


# try:
#     a = 1/3
# except Exception as e:
#     print(e)
# else:
#     print("啥时候执行")
# finally:
#     print("不管什么都执行")
# str1 = int(input("请输入一个数字："))
# if str1 == 1:
#     raise ValueError("输入数字为1")
# else:
#     print("输入数字不为1")

# 自定义异常
class DefineError(Exception):
    def __init__(self, msg):
        self.msg = msg

    def __str__(self):
        return self.msg

try:
    raise DefineError("XXX错误")
except DefineError as e:
    print(e)

